const $api = require('../../utils/api.js').API;
const { $Toast } = require('../../dist/base/index');
Page({
    data: {
        value: 0,
        text: '',
        openid: ''
    },

    onLoad(e) {
        console.log('grade onload')
        this.setData({
            openid: e.openid
        })
    },

    // 打分触发
    onChange(e) {
        this.setData({
            value: e.detail
        })
    },

    // 输入意见触发
    onInput(e) {
        this.setData({
            text: e.detail.value
        })
    },

    // 提交
    submit() {
        if (this.data.value === 0)
            $Toast({
                content: '请评分后提交哦~',
            });
        else {
            $api.rate({
                openid: this.data.openid,
                value: this.data.value,
                text: this.data.text
            })
                .then(res => { 
                    $Toast({
                        content: '提交成功',
                        type: 'success'
                    });
                })
                .catch(err => console.log(err))
        }
    }
})